<template>
  <view>
    <!-- 专题背景 -->
    <view class="album_bg">
      <img :src="album.cover" alt="" mode="widthFix" />
      <view class="album_info">
        <view class="album_name">{{ album.name }}</view>
        <view class="album_btn">关注专辑</view></view
      >
    </view>
    <!-- 专题作者 -->
    <view class="album_author">
      <view class="album_author_info">
        <img :src="album.user.avatar" alt="" mode="widthFix" />
        <view class="author_name"> {{ album.user.name }}</view>
      </view>
      <text class="album_author_desc">{{ album.desc }}</text>
    </view>
    <!-- 列表结束 -->
    <view class="album_list">
      <view class="album_item" v-for="(item,index) in wallpaper" :key="item.id">
        <go-detail :list="wallpaper" :index="index">
        <img
          mode="aspectFill"
          :src="item.thumb + item.rule.replace('$<Height>', 360)"
          alt=""
        /></go-detail>
      </view>
    </view>
  </view>
</template>

<script>
import goDetail from "@/components/goDetail";
export default {
  components: {
    goDetail,
  },
  onLoad(options) {
    //console.log(options);
    this.id = options.id;
    //this.id ="5d5f8e45e7bce75ae7fb8278" ;
    this.getList();
  },
  onReachBottom() {
    if (this.hasMore) {
      this.params.skip += this.params.limit;
      this.params.first = 0;
      this.getList();
    } else {
      uni.showToast({
        title: "没有更多了",
        icon: "none",
      });
    }
  },
  data() {
    return {
      params: {
        limit: 30,
        order: "new",
        skip: 0,
        //当为1时返回值有album 为0 只有wallpaper数组
        first: 1,
      },
      id: -1,
      album: [],
      wallpaper: [],
      hasMore: true,
    };
  },
  methods: {
    async getList() {
      const res = await this.request(
        `/image/v1/wallpaper/album/${this.id}/wallpaper`,
        this.params,
      );
      if (res.code === 0) {
        if (Object.keys(this.album).length === 0) {
          this.album = res.res.album;
        }

        if (res.res.wallpaper.length === 0) {
          this.hasMore = false;
          uni.showToast({
            title: "没有更多了",
            icon: "none",
          });
          return;
        }
        this.wallpaper = [...this.wallpaper, ...res.res.wallpaper];
      }
    },
  },
};
</script>

<style lang="scss">
.album_bg {
  position: relative;

  .album_info {
    position: absolute;
    width: 100%;
    left: 0;
    bottom: 0;
    display: flex;
    justify-content: space-between;
    height: 80rpx;
    color: #fff;
    padding: 0 15rpx;
    .album_name {
      font-style: 40rpx;
    }

    .album_btn {
      background-color: $color;
      width: 152rpx;
      height: 60rpx;
      display: flex;
      justify-content: center;
      align-items: center;
      border-radius: 10rpx;
    }
  }
}
.album_author {
  padding: 10rpx;
  .album_author_info {
    display: flex;
    img {
      width: 50rpx;
    }

    .author_name {
      color: #000;
      margin-left: 15rpx;
    }
  }
}
.album_list {
  display: flex;
  flex-wrap: wrap;
  .album_item {
    width: 33.3333%;
    border: 3px solid white;
    img{
      height: 160rpx;
    }
  }
}
</style>
